﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SocialShare.BusinessLogicLayer;
using SocialShare.BusinessEntities;
using SocialShare.BLL;

namespace SocialShare.DAL.Facades
{
    [System.ComponentModel.DataObject(true)]
    public class BlogFacade
    {
        private SocialShare_BlogsBLL bll = null;
        private SocialShare_Blog_CommentsBLL commentsBll = null;

        public BlogFacade() { }

        private SocialShare_BlogsBLL BlogInstance
        {
            get
            {
                if (bll == null)
                {
                    return bll = new SocialShare_BlogsBLL();
                }
                else
                {
                    return bll;
                }
            }

        }

        private SocialShare_Blog_CommentsBLL BlogCommentsInstance
        {
            get
            {
                if (commentsBll == null)
                {
                    return commentsBll = new SocialShare_Blog_CommentsBLL();
                }
                else
                {
                    return commentsBll;
                }
            }

        }

        #region Functions

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<BlogPost> GetAllActiveBlogPosts(Int32 startRowIndex = default(Int32), Int32 maximumRows = default(Int32))
        {
            return this.BlogInstance.GetAllSocialShareActiveBlogsPaged(startRowIndex, maximumRows);
        }

        public Int32 GetTotalCountActiveBlogPosts(Int32 startRowIndex = default(Int32), Int32 maximumRows = default(Int32))
        {
            return this.BlogInstance.GetTotalCountForAllActiveSocialShareBlogs(startRowIndex, maximumRows);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<BlogPost> GetAllActiveBlogPostsByMember(Int32 startRowIndex = default(Int32), Int32 maximumRows = default(Int32), String blogName=default(String))
        {
            return this.BlogInstance.GetAllActiveBlogPostsByMember(startRowIndex, maximumRows, blogName);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public Int32 GetTotalCountActiveBlogPostsByMember(Int32 startRowIndex = default(Int32), Int32 maximumRows = default(Int32), String blogName = default(String))
        {
            return this.BlogInstance.GetTotalCountActiveBlogPostsByMember(startRowIndex, maximumRows, blogName);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public BlogPost GetBlogPostById(Int32 blogId)
        {
            return this.BlogInstance.GetSocialShareBlogByBlogId(blogId);
        }

        public Int32 SaveBlog(SocialShare_Blogs blog)
        {
            return this.BlogInstance.CreateNewSocialShare_Blogs(blog);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<SocialShare_Blog_Comments> GetAllBlogCommentsById(Int32 blogId,Int32 startRowIndex = default(Int32), Int32 maximumRows = default(Int32))
        {
            return this.BlogCommentsInstance.GetSocialShare_Blog_CommentsByBlogIdPaged(blogId, "CreateDate DESC", startRowIndex, maximumRows);
        }

        public Int32 GetTotalCountAllBlogCommentsById(Int32 blogId, Int32 startRowIndex = default(Int32), Int32 maximumRows = default(Int32))
        {
            return this.BlogCommentsInstance.GetTotalCountForAllSocialShare_Blog_CommentsByBlogId(blogId, "CreateDate DESC", startRowIndex, maximumRows);
        }

        public List<BlogPost> GetRecentBlogs()
        {
            return this.BlogInstance.GetAllSocialShareActiveBlogsPaged(0, 5);
        }

        public Int32 GetAllBlogCount()
        {
            return this.BlogInstance.GetAllSocialShare_Blogs().Count;
        }

        public List<BlogPost> GetAllBlogPosts(String sortOrder = default(String), Int32 startRowIndex = default(Int32), Int32 maximumRows = default(Int32))
        {
            return this.BlogInstance.GetAllBlogPosts(sortOrder, startRowIndex, maximumRows);
        }

        public void UpdateBlog(SocialShare_Blogs post)
        {
            this.BlogInstance.UpdateSocialShare_Blogs(post);
        }

        public SocialShare_Blogs GetBlogById(Int32 blogId)
        {
            return this.BlogInstance.GetSocialShare_BlogsByBlogId(blogId);
        }

        public Tuple<Int32, Int32> GetApproveDisapprveTotal()
        {
            return this.BlogInstance.GetApproveDisapprveTotal();
        }

        public List<CountReport> GetTotalPostsByMonth()
        {
            return this.BlogInstance.GetTotalPostsByMonth();
        }

        public List<BlogPost> GetAllActiveBlogPostsByMember(String userId = default(String))
        {
            return this.BlogInstance.GetAllActiveBlogPostsByMember(userId);
        }

        public void DeleteBlog(String blogPostId)
        {
            List<Int32> blogIdsToDelete=new List<Int32>();
            blogIdsToDelete.Add(Convert.ToInt32(blogPostId));
            this.BlogInstance.DeleteSocialShare_Blogs(blogIdsToDelete);
        }

        #endregion
    }
}
